extends Node2D


func _ready():
	$AnPaiPanel/WeekVbox/Week1.connect("pressed",$ActivityPanel,"on_show",[0])
	$AnPaiPanel/WeekVbox/Week2.connect("pressed",$ActivityPanel,"on_show",[1])
	$AnPaiPanel/WeekVbox/Week3.connect("pressed",$ActivityPanel,"on_show",[2])
	$AnPaiPanel/WeekVbox/Week4.connect("pressed",$ActivityPanel,"on_show",[3])
	
	# 同步日历显示
	$ActivityPanel/MenuClass/Hbox/GeDou.connect("pressed",$AnPaiPanel/WeeksShow,"on_show",["gedou"])
	$ActivityPanel/MenuClass/Hbox/Magic.connect("pressed",$AnPaiPanel/WeeksShow,"on_show",["magic"])
	$ActivityPanel/MenuClass/Hbox/Music.connect("pressed",$AnPaiPanel/WeeksShow,"on_show",["music"])
	$ActivityPanel/MenuClass/Hbox/WenXue.connect("pressed",$AnPaiPanel/WeeksShow,"on_show",["wenxue"])
	$ActivityPanel/MenuAction/Hbox/Work.connect("pressed",$AnPaiPanel/WeeksShow,"on_show",["work"])
	$ActivityPanel/MenuAction/Hbox/Reset.connect("pressed",$AnPaiPanel/WeeksShow,"on_show",["reset"])
	# 全局变量同步
	$ActivityPanel/MenuClass/Hbox/GeDou.connect("pressed",$"/root/Global","on_week_update",["gedou"])
	$ActivityPanel/MenuClass/Hbox/Magic.connect("pressed",$"/root/Global","on_week_update",["magic"])
	$ActivityPanel/MenuClass/Hbox/Music.connect("pressed",$"/root/Global","on_week_update",["music"])
	$ActivityPanel/MenuClass/Hbox/WenXue.connect("pressed",$"/root/Global","on_week_update",["wenxue"])
	$ActivityPanel/MenuAction/Hbox/Work.connect("pressed",$"/root/Global","on_week_update",["work"])
	$ActivityPanel/MenuAction/Hbox/Reset.connect("pressed",$"/root/Global","on_week_update",["reset"])
	
	if not Global.data.empty():
		print_debug("读取存档 ",Global.data)
		$StatusPanel/Age.text = "年龄" + str(Global.data["age"])
		$Date.text = str(Global.data["year"]) + "年" + str(Global.data["month"]) + "月"
		$AnPaiPanel/Date.text = str(Global.data["year"]) + "年" + str(Global.data["month"]) + "月"
		$CoinBg/Label.text = str(Global.data["coin"])
		$AnPaiPanel/CoinBg/Label.text = str(Global.data["coin"])
		$AnPaiPanel/PiLaoBg/PiLaoValue.text = str(Global.data["pilao"])
		$AnPaiPanel/PiLaoBg/TiLiValue.text = str(Global.data["tili"])
		
		$StatusPanel/VBoxContainer/ZhiliBar/Label.text = "智力" +str( Global.data["zhili"])
		$StatusPanel/VBoxContainer/ShenliBar/Label.text = "神力" + str(Global.data["shenli"])
		$StatusPanel/VBoxContainer/QizhiBar/Label.text = "气质" + str(Global.data["qizhi"])
		$StatusPanel/VBoxContainer/TiliBar/Label.text = "体力" + str(Global.data["tili"])
		$StatusPanel/VBoxContainer/Pilaobar/Label.text = "疲劳" + str(Global.data["pilao"])
		$StatusPanel/VBoxContainer/ZhiliBar/ProgressBar.value = Global.data["zhili"]
		$StatusPanel/VBoxContainer/ShenliBar/ProgressBar.value = Global.data["shenli"]
		$StatusPanel/VBoxContainer/QizhiBar/ProgressBar.value = Global.data["qizhi"]
		$StatusPanel/VBoxContainer/TiliBar/ProgressBar.value = Global.data["tili"]
		$StatusPanel/VBoxContainer/Pilaobar/ProgressBar.value = Global.data["pilao"]
		
		$StatusPanel/TiXing.text = "体型 " + str(Global.data["tixing"]) 
		if Global.data["pilao"] > Global.data["tili"]:
			$TooTired.popup()
			$ActivityPanel/MenuAction/Hbox/Learn.disabled = true
			$ActivityPanel/MenuAction/Hbox/Work.disabled = true
		else:
			$ActivityPanel/MenuAction/Hbox/Learn.disabled = false
			$ActivityPanel/MenuAction/Hbox/Work.disabled = false
		if Global.data["end"] == true:
			get_tree().change_scene("res://scene/EndCG.tscn")
	pass


func _on_MainButton_pressed():
	get_tree().change_scene("res://scene/Main.tscn")
	pass # Replace with function body.


func _on_MainButton2_pressed():
	$StatusPanel.show()
	pass # Replace with function body.


func _on_AnPaiButton_pressed():
	$AnPaiPanel.show()
	pass # Replace with function body.
